<?php
App::uses('AppController', 'Controller');
/**
 * Introductions Controller
 *
 * @property Introduction $Introduction
 * @property PaginatorComponent $Paginator
 */
class IntroductionsController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');

/**
 * index method
 *
 * @return void
 */
	public function admin_index() {
	
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Introduction->save($this->request->data)) {
			$this->Session->setFlash(__('Cập nhật thành công '),'backend/green',array('redirect'=>''));
				
				return $this->redirect(array('action' => 'admin_index'));
			} else {
				$this->Session->setFlash(__('Could not be saved. Please, try again.'));
			}
		} else {
		    $this->request->data= $this->Introduction->find('first',array('conditions'=>array("Introduction.active"=>1))); 
			
		}
		
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Introduction->exists($id)) {
			throw new NotFoundException(__('Invalid introduction'));
		}
		$options = array('conditions' => array('Introduction.' . $this->Introduction->primaryKey => $id));
		$this->set('introduction', $this->Introduction->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Introduction->create();
			if ($this->Introduction->save($this->request->data)) {
				$this->Session->setFlash(__('The introduction has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The introduction could not be saved. Please, try again.'));
			}
		}
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->Introduction->exists($id)) {
			throw new NotFoundException(__('Invalid introduction'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Introduction->save($this->request->data)) {
				$this->Session->setFlash(__('The introduction has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The introduction could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('Introduction.' . $this->Introduction->primaryKey => $id));
			$this->request->data = $this->Introduction->find('first', $options);
		}
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->Introduction->id = $id;
		if (!$this->Introduction->exists()) {
			throw new NotFoundException(__('Invalid introduction'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->Introduction->delete()) {
			$this->Session->setFlash(__('The introduction has been deleted.'));
		} else {
			$this->Session->setFlash(__('The introduction could not be deleted. Please, try again.'));
		}
		return $this->redirect(array('action' => 'index'));
	}}
